package cn.com.dhcc.app.pub.module.codematic.service;


import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

import org.springframework.util.ResourceUtils;

import cn.com.dhcc.app.core.util.FreemarkerUtil;
import cn.com.dhcc.app.pub.module.codematic.vo.Bean;

public class ServiceGenerator{
	public static void generate(String appRoot,Class<?> clazz, Bean entity) throws Exception {
		File template = ResourceUtils.getFile("classpath:template/codematic/service_template.ftl");
		File pkg = ResourceUtils.getFile(appRoot + "/codematic/main/java/"+ (entity.getAppPkg() + ".service." + entity.getServicePkg()).replaceAll("\\.", "/"));
		if(!pkg.exists()){
			pkg.mkdirs();
		}
		File javaFile = new File(pkg.getAbsoluteFile() + "/" + entity.getBeanName()+ "Service.java");
		Writer fileWriter = new FileWriter(javaFile);
		FreemarkerUtil.flushData(template.getAbsolutePath(), fileWriter, entity);
	}
}
